
/**
 * 倒计时
 * @author Jiangdw
 * @createDate 2016-03-16
 */
;(function($, window, document, undefined){
    
	$.fn.countdown = function(options){
		var $wrapper = $(this),
			_$opts = $.extend({}, $.fn.countdown.defaults, options),
			d = 0, h = 0, m = 0, s = 0, html = '',
			endTime = new Date(_$opts.time),
			pattern = _$opts.pattern;
		setInterval(function(){
			var nowTime = new Date(),
				t = endTime.getTime() - nowTime.getTime();
			if(t > 0){
				d = Math.floor(t / 1000 / 60 / 60 / 24);
				h = Math.floor(t / 1000 / 60 / 60 % 24);
				m = Math.floor(t / 1000 / 60 % 60);
				s = Math.floor(t / 1000 % 60);
			}
			html = pattern.replace('d',d).replace('h',h).replace('m',m).replace('s',s);
			$wrapper.html(html);
		}, 1000);
		return this;
	};
	
	$.fn.countdown.defaults = {
		time: '',//格式如：2016/03/17 09:50:25
		pattern: 'd 天  h 时 m 分 s 秒'
	};
	
})(jQuery, window, document);